package top.yeyusmile.quartz;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.yeyusmile.common.RobotConfig;
import top.yeyusmile.common.TypeConstant;
import top.yeyusmile.pojo.MyQQMessage;
import top.yeyusmile.service.ConvenientService;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author 夜雨
 * @Web www.yeyusmile.top
 * @date 2022/3/17 8:43
 */
@Component
@Slf4j
public class HourJob {

    @Autowired
    private RobotConfig robotConfig;

    @Autowired
    private ConvenientService convenientService;

   // @Scheduled(cron = "0 * * * * ?")
    @Scheduled(cron = "0 0 * * * ?")
    public void executeJob() {
        // convenientService.quotation(message);

        for (String group : robotConfig.getGroupManger()) {
            MyQQMessage myQQMessage = new MyQQMessage();
            myQQMessage.setMqMsg("随机语录");
            myQQMessage.setMqFromid(group.trim());
            myQQMessage.setMqFromqq("");
            myQQMessage.setMqType(TypeConstant.MSGTYPE_GROUP);
            myQQMessage.setMqRobot(robotConfig.getRobotQQ());
            log.info("HourJob is running:{}", myQQMessage);
            convenientService.quotation(myQQMessage);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

}

